package com.wframe.project.former.task;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.frame.database.JdataBean;
import com.wframe.project.jnd.extinterface.sms.SmsUtil;
import com.wframe.project.jnd.services.SmsPushService;

/**
 * 定时短信发送服务
 *
 * @author lenovo
 */
@Component
public class SmsPushTask {

    @Autowired
    SmsPushService smsPushService;
    List<String> ids = new ArrayList<String>();
    SmsUtil smsutil = new SmsUtil();

    @RedisLock("smsPushTask")
    public void exectask() {
        try {
            List<JdataBean> list = smsPushService.querySmsPush(100);
            ids.clear();
            for (JdataBean bean : list) {
                ids.add(bean.getString("id"));
                try {
                    smsutil.sendSms(bean.getString("phone"), bean.getString("content"));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            smsPushService.tagSmsPush(ids.toArray(new String[]{}));
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    }
}
